package com.it.mybatis.service.serviceImpl;

import com.it.mybatis.dao.CompanyXmlDao;
import com.it.mybatis.domain.Company;
import com.it.mybatis.model.ApiModel;
import com.it.mybatis.query.CompanyQuery;
import com.it.mybatis.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author LHN
 * @ClassName CompanyServiceImpl
 * @Date 2021/10/23
 * @Description }
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    CompanyXmlDao companyXmlDao;
    @Override
    public ApiModel findBy(CompanyQuery query) {
        List<Company> companies = companyXmlDao.findBy(query);
        if(!CollectionUtils.isEmpty(companies)){
            return ApiModel.ok(companies);
        }
        return ApiModel.fail();
    }

    @Override
    public ApiModel findAll() {
        List<Company> companies = companyXmlDao.findAll();
        if(!CollectionUtils.isEmpty(companies)){
            return ApiModel.ok(companies);
        }
        return ApiModel.fail();
    }

    @Override
    public ApiModel deleteById(Integer id) {

        Integer integer = companyXmlDao.deleteById(id);
        if(integer>0){
            return ApiModel.ok();
        }
        return ApiModel.fail();
    }

    @Override
    public ApiModel insertCompany(Company company) {
        Integer integer = companyXmlDao.insertCompany(company);
        if(integer>0){
            return ApiModel.ok();
        }
        return ApiModel.fail();
    }
}
